//package com.cwm.handler;
//
//import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
//import com.alibaba.csp.sentinel.slots.block.BlockException;
//import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
//import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
//import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
//import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
//import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
//import com.alibaba.fastjson.JSON;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * 没有配资源，默认Block异常处理（只能是Block异常）
// */
//@Slf4j
//@Component
//public class CustomBlockExceptionHandler implements BlockExceptionHandler {
//
//    @Autowired
//    private ObjectMapper objectMapper;
//
//    @Override
//    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws Exception {
//        httpServletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value());
//        if (e instanceof FlowException) {
//            log.error("FlowException 普通服务限流，资源信息：" + JSON.toJSONString(e.getRule()));
//            httpServletResponse.setStatus(org.springframework.http.HttpStatus.TOO_MANY_REQUESTS.value());
//            ResponseUtil.responseFailed(objectMapper, httpServletResponse, 1000, "API interface limited flow.");
//        } else if (e instanceof DegradeException) {
//            log.error("DegradeException 普通服务降级，资源信息：" + JSON.toJSONString(e.getRule()));
//            ResponseUtil.responseFailed(objectMapper, httpServletResponse, 1001, "API interface has been degraded.");
//        } else if (e instanceof ParamFlowException) {
//            ParamFlowException ex = (ParamFlowException) e;
//            log.error("ParamFlowException 参数热点限流，资源名={}，参数={}，资源信息={}", ex.getResourceName(), ex.getLimitParam(), JSON.toJSONString(ex.getRule()));
//            ResponseUtil.responseFailed(objectMapper, httpServletResponse, 1002, "API interface limited flow by params.");
//        } else if (e instanceof AuthorityException) {
//            log.error("AuthorityException 授权规则，资源信息：" + JSON.toJSONString(e.getRule()));
//            ResponseUtil.responseFailed(objectMapper, httpServletResponse, 1003, "API interface limited by authority.");
//        } else if (e instanceof SystemBlockException) {
//            SystemBlockException systemBlockException = (SystemBlockException) e;
//            log.error("SystemBlockException，资源名：{}，资源类型：{}", systemBlockException.getResourceName(), systemBlockException.getRuleLimitApp());
//            ResponseUtil.responseFailed(objectMapper, httpServletResponse, 1004, "API interface limited by system.");
//        }
//    }
//}
